package gold.contest;

import gold.utils.InputUtil;

import java.util.*;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC5990 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public List<Integer> findLonely(int[] nums) {
            Map<Integer, Integer> cnt = new HashMap<>();
            for (int num : nums) {
                cnt.put(num, cnt.getOrDefault(num, 0) + 1);
            }

            List<Integer> res = new ArrayList<>();
            for (Integer num : cnt.keySet()) {
                if (cnt.get(num) == 1 && !cnt.containsKey(num - 1) && !cnt.containsKey(num + 1)) res.add(num);
            }
            return res;
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.findLonely(InputUtil.toIntegerArray("[10,6,5,8]")));
        System.out.println(solution.findLonely(InputUtil.toIntegerArray("[1,3,5,3]")));
    }

    public static void main(String[] args) throws Exception {
        LC5990 an = new LC5990();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
